<template>
	<view>
		<u-card padding="16">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="12" text-align="center" v-if="HxStoragePutDetailedParam.photofile">
							<view style="height: 400rpx;" class="u-line-1 u-m-t-10"
								@click="viewImage(HxStoragePutDetailedParam.photofile)">
								<u-image width="450rpx" height="400rpx"
									:src="imgs(HxStoragePutDetailedParam.photofile)"></u-image>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="u-m-t-5 weikaishi3 lanse">
								<span>
									<u-icon name="order" size="30" labelSize="15px" labelColor="#000000"></u-icon>
									{{HxStoragePutDetailedParam.goodsName}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span>
									<u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000" label="商品码"
										color="#000000"></u-icon>：{{HxStoragePutDetailedParam.goodsPcode69}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span>
									<u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000" label="商品编号">
									</u-icon>：{{HxStoragePutDetailedParam.goodsNumber}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span>
									<u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000" label="规格">
									</u-icon>：{{HxStoragePutDetailedParam.goodsSpecs}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="7">
							<view class="weikaishi6">
								<span>
									<u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="数量"
										color="#000000"></u-icon>
									：{{HxStoragePutDetailedParam.num}}{{HxStoragePutDetailedParam.unit}}/{{HxStoragePutDetailedParam.putVolume}}方
								</span>
							</view>
						</u-col>
						<u-col span="5" v-if="HxStoragePutDetailedParam.num == HxStoragePutDetailedParam.realNum">
							<view class="weikaishi6 yiwancheng">
								<span>
									<u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#00c300"
										label="实入" color="#00c300"></u-icon>：{{HxStoragePutDetailedParam.realNum}}
								</span>
							</view>
						</u-col>
						<u-col span="5" v-else>
							<view class="weikaishi6">
								<span>
									<u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#000000"
										label="实入" color="#000000"></u-icon>：{{HxStoragePutDetailedParam.realNum}}
								</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="3" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>托号</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>应入</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>实入</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>库位</span>
							</view>
						</u-col>
						<u-col span="3" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>生产日期</span>
							</view>
						</u-col>
					</u-row>
					<u-row v-for="(item,index) in dataList" :key="index" @click="quality(item)">
						<u-col span="3" text-align="center" v-if="item.putState == '待质检'">
							<view class="weikaishi lanse u-m-t-25 huanhang">
								<span>{{item.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="center" v-else>
							<view class="weikaishi yiwancheng u-m-t-25 huanhang">
								<span>{{item.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.num}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.realNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.positionNumber}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.detailedDate}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="center">
							<view class="jiange">
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<view>
			<u-toast ref="uToast" />
		</view>
		<u-popup v-model="popupShow" mode="center" closeable width="550rpx" height="550rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">质检入库，单位：{{fromd.unit}}</view>
			<view class=" u-m-20">
				<u-input v-model="fromd.positionNumber" :border="true" placeholder="请输入库位" />
			</view>
			<view class=" u-m-20">
				<u-input v-model="fromd.realNum" type="digit" :border="true" placeholder="请输入实入数" />
			</view>
			<view class=" u-m-20">
				<!-- <u-input v-model="fromd.approveUnit" type="select" @click="getT1()" placeholder="请选择批复单位"
					:border="true" /> -->
					<u-input v-model="fromd.approveUnit" type="text" placeholder="请输入批复单位"
						:border="true" />
			</view>
			<view class=" u-m-20">
				<u-input v-model="fromd.detailedDate" type="select" @click="getT()" placeholder="选择生产日期"
					:border="true" />
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<view>
			<u-calendar v-model="show" mode="date" max-date="2070-01-01" @change="change"></u-calendar>
		</view>
		<view>
			<u-select v-model="shows" :list="approveUnitList" :border="true" placeholder="请选择批复单位"  @confirm="change1">
			</u-select>
		</view>

	</view>
</template>
<script>
	import config from '../../config.js'
	export default {
		data() {
			return {
				storageNumber: '',
				goodsId: '',
				HxStoragePutDetailedParam: {},
				dataList: [],
				keyword: '',
				fromd: {},
				show: false,
				shows: false,
				popupShow: false,
				approveUnitList: [],
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif

			this.storageNumber = open.storageNumber
			this.goodsId = open.goodsId
			console.log(open)


		},
		onShow() {
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		mounted() {
			// 在组件挂载时获取数据
			this.fetchData();
		},
		methods: {
			imgs(fileId) {
				return config.root + 'system/previewa/' + fileId
			},
			viewImage(fileId) {
				let arr = []
				let img = config.root + 'system/previewa/' + fileId
				arr.push(img)
				uni.previewImage({
					urls: arr,
				});
			},
			change(e) {
				this.fromd.detailedDate = e.result
			},
			getT() {
				this.show = true
			},
			getT1() {
				this.shows = true
			},
			change1(res) {
				this.fromd.approveUnit = res[0].value
				console.log("res:",res[0].value)
			},
			define() {
				if (this.fromd.realNum != 0) { 
				if (typeof this.fromd.positionNumber == 'undefined' || this.fromd.positionNumber == null || this.fromd
					.positionNumber == "") {
					uni.showToast({
						title: "请输入库位",
						icon: 'none'
					})
					return
				}
				if (typeof this.fromd.realNum == 'undefined' || this.fromd.realNum == null || this.fromd.realNum == "") {
					uni.showToast({
						title: "请输入实际数量",
						icon: 'none'
					})
					return
				}
				if (typeof this.fromd.approveUnit == 'undefined' || this.fromd.approveUnit == null || this.fromd
					.approveUnit == "") {
					uni.showToast({
						title: "请输入批复单位",
						icon: 'none'
					})
					return
				}
				if (typeof this.fromd.detailedDate == 'undefined' || this.fromd.detailedDate == null || this.fromd
					.detailedDate == "") {
					uni.showToast({
						title: "请选择生产日期",
						icon: 'none'
					})
					return
				}
				}
				this.$http.post('/rest/HxStorageReturn/return_put', {}, {
					params: {
						id: this.fromd.id,
						positionNumber: this.fromd.positionNumber,
						realNum: this.fromd.realNum,
						detailedDate: this.fromd.detailedDate,
						approveUnit: this.fromd.approveUnit,
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '入库成功',
							type: 'success'
						})
						this.popupShow = false
						setTimeout(() => {
							this.refresh()
						}, 600)
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			quality(item) {
				if (item.putState == '待质检') {
					this.fromd = item
					this.popupShow = true

				}
			},
			fetchData() {
				this.$http.post('/rest/HxStorageReturn/detailedGoodsId', {}, {
					params: {
						goodsId: this.goodsId,
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					console.log(res.data.data)
					const lists = res.data.data.map(item => {
					  const units = [item.jibenUnit, item.kcUnit, item.cgUnit, item.pfUnit, item.psUnit];
					  const uniqueUnits = [...new Set(units)]; // 去重
					  return uniqueUnits.map(unit => ({
					    value: unit,
					    label: unit
					  }));
					});
					this.approveUnitList = lists[0];

				})
			},
			refresh() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/detailedSum', {}, {
					params: {
						storageNumber: this.storageNumber,
						goodsId: this.goodsId
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.data != null && res.data.data != '') {
						this.HxStoragePutDetailedParam = res.data.data
						this.$http.post('/rest/HxStoragePut/detailedlist', {}, {
							params: {
								storageNumber: this.storageNumber,
								goodsId: this.goodsId
							},
							header: {
								'Authorization': uni.getStorageSync('token'),
							}
						}).then(res => {
							this.dataList = res.data.data
						})
					}
				})
			},
		},
	}
</script>
<style lang="scss">
	.huanhang {
		word-break: break-all;
	}

	.jiange {
		border-bottom: 1px solid #e1e1e1;
	}
</style>
